//
//  NNTabBarController.swift
//  CommonTool
//
//  Created by tenroadshow on 12.1.22.
//

import UIKit

class NNTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        commonInit()
        addChild(controller: NNHomeViewController(), title: "Home")
    }
    
    fileprivate func addChild(controller: UIViewController, title: String) {
        
        controller.tabBarItem.title = title
        controller.tabBarItem.image = UIImage(named: "tn_tabbar_mine_n")?.withRenderingMode(.alwaysOriginal)
        controller.tabBarItem.selectedImage = UIImage(named: "tn_tabbar_mine_n")?.withRenderingMode(.alwaysOriginal)
        let navigationController = NNNavigationController(rootViewController: controller)
        addChild(navigationController)
        
    }
    
    
    
    fileprivate func commonInit() {
        tabBar.isTranslucent = false
        
        if #available(iOS 15, *) {
            let barAppearance = UITabBarAppearance.init()
            barAppearance.backgroundColor = UIColor.white
//            barAppearance.shadowImage = UIImage()
            // 设置选中attributes
            barAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor: UIColor(hexString: "c0098FF")!
            ]
            barAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [
                NSAttributedString.Key.foregroundColor: UIColor(hexString: "c202020")!
            ]
            self.tabBar.scrollEdgeAppearance = barAppearance
            self.tabBar.standardAppearance = barAppearance
        }else {
            self.tabBar.backgroundImage = UIImage(color: .white)
//            self.tabBar.shadowImage = UIImage()
            
            let tabbar = UITabBar.appearance()
            tabBar.tintColor = UIColor(hexString: "c0098FF")
            tabbar.unselectedItemTintColor = UIColor(hexString: "c202020")!

            let item = UITabBarItem.appearance()
            item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor(hexString: "c202020")!], for: .normal)
            item.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor(hexString: "c0098FF")!], for: .selected)
        }
    }

}
